

from modelscope import AutoModelForCausalLM, AutoTokenizer
from modelscope.tools import train

model_name = "/home/aresen/1project/2python/hub/Qwen2.5-0.5B-Instruct"

model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)

prompt = "Joy can read 8 pages of a book in 20 minutes. How many hours will it take her to read 120 pages?"

messages = [
    {"role": "user", "content": prompt}
]

text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]

print(response)


from datasets import load_dataset, DatasetDict, Dataset
from datasets.features import features
from formatter import test

data = load_dataset('openai/gsm8k', 'main')

# DatasetDict({
#     train: Dataset({
#         features: ['question', 'answer'],
#         num_rows: 7473
#     }),
#     test: Dataset({
#         features: ['question', 'answer'],
#         num_rows: 1319
#     })
# })
#
# print(data['train'][0])




